/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 18:06:15
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-03-28 15:17:22
 */

import { cloneDeep } from "lodash-es"
import { operateFormConfig } from "../../admissionManagement/config"

export const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《房间信息导入模板》',
							link: true,
							url: 'view_dpOrgRoomInfo_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入信息',
			description: '',
			uploadTip: '房间信息',
			active: 2,
			url: 'view_dpOrgRoomInfo_import',
			code: 3027,
			rules: [
				{
					label: '导入规则说明:',
					children: [
						{
							label: '(1)导入模式为“覆盖导入”，待导入的信息会覆盖平台已存在的',
						},
					],
				},
			],
		},
	],
	dataType: 9,
}

// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '养老机构', prop: 'organizationName' },
		{ label: '所属楼栋', prop: 'belongBuilding' },
		{ label: '所属楼层', prop: 'floor' },
		{ label: '房间号', prop: 'roomCode' },
		{ label: '床位数', prop: 'maxBedNum' },
		{ label: '房间面积', prop: 'roomArea' },
		{ label: '备注', prop: 'roomNote' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	column: [
		{
			label: '养老机构',
			prop: 'creditCode',
			propName: 'organizationName',
			type: 'remoteSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'creditCode',
			filterLabel: 'organizationName',
			multiple: false,
			changeField: true,
			viewDisplay: false,
			rules: [{ required: true, message: '请输入当前所在单位' }],
			span: 12,
		},
		{
			label: '楼栋信息',
			prop: 'buildInfo',
			propName: 'buildInfoText',
			type: 'BuildRoomBed',
			deepLevel: 1,
			span: 12,
		},
		{ label: '房间号', prop: 'roomCode', span: 12, rules: [{ required: true, message: '请输入房间号' }] },
		{ label: '房间总面积', prop: 'roomArea', span: 12 },
		{ label: '床位数', prop: 'maxBedNum', span: 12 },
		{ label: '平均面积', prop: 'bedAvgArea', span: 12, disabled: true },
		{
			label: '是否有窗户',
			prop: 'isWindow',
			propName: 'isWindowLabel',
			changeField: true,
			code: 'COMMON_FLAG',
			type: 'remoteSelect',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
		},
		{
			label: '朝向',
			prop: 'toward',
			propName: 'towardLabel',
			changeField: true,
			code: 'TOWARD',
			type: 'remoteSelect',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
		},
		{ label: '备注', type: 'textarea', prop: 'roomNote', span: 24 },
	],
}

const formateBuilData = (form) => {
	let query = {
		...form,
		buildInfo: undefined,
	}
	if (form.buildInfo && form.buildInfoText) {
		const buildName = form.buildInfoText.split('/')
		query.belongBuilding = buildName[0]
		query.floor = form.buildInfo[1]
	}
	return query
}

export const baseConfig = {
	pageName: '机构房间管理',
	// 数据字典
	dictcodes: ['COMMON_FLAG', 'TOWARD'],
	addLabel: '新增房间',
	rowKey: 'id',
	tipLabel: 'roomCode',
	api: {
		index: 'view_dpOrgRoomInfo_page',
		detail:'view_dpOrgRoomInfo_view',
		add: 'view_dpOrgRoomInfo_add',
		edit: 'view_dpOrgRoomInfo_edit',
		delete: 'view_dpOrgRoomInfo_del',
		import: 'view_dpOrgRoomInfo_import',
	},
	auth: {
		index: 'view_dpOrgRoomInfo_page',
		detail:'view_dpOrgRoomInfo_view',
		add: 'view_dpOrgRoomInfo_add',
		edit: 'view_dpOrgRoomInfo_edit',
		delete: 'view_dpOrgRoomInfo_del',
		import: 'view_dpOrgRoomInfo_import',
	},
	// 当前行操作按钮
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type:"primary",
			operate: 'detail',
			auth: 'view_dpOrgBulidingInfo_page',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type:"primary",
			operate: 'edit',
			auth: 'view_dpOrgBulidingInfo_edit',
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type:"danger",
			operate: 'delete',
			auth: 'view_dpOrgBulidingInfo_del',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
	},
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '楼栋信息',
				prop: 'buildInfo',
				propName: 'buildInfoText',
				type: 'BuildRoomBed',
				deepLevel: 1,
				span: 8,
			},
			{ label: '房间号', prop: 'roomCode', span: 6 },
		],
	},
	tableConfig,
	detailConfig: formConfig,
	formConfig,
	importConfig,
	operateFormate:async (form,type) => {
		let item = cloneDeep(form)
		return Promise.resolve({
			...item,
			buildInfo: [item.belongBuilding, `${item.floor}`],
			buildInfoText: [item.belongBuilding, item.floor].join('/'),
		})
	},
	onLoadFormate(arr) {
		return new Promise((resolve, reject) => {
			const tableData = arr.map((item) => {
				return {
					...item,
					buildInfo: [item.belongBuilding, `${item.floor}`],
					buildInfoText: [item.belongBuilding, item.floor].join('/'),
				}
			})
			resolve(tableData)
		})
	},
	beforeOnLoadFormate(form) {
		return new Promise((resolve, reject) => {
			resolve(formateBuilData(form))
		})
	},
	saveFormate(form) {
		return new Promise((resolve, reject) => {
			resolve(formateBuilData(form))
		})
	},
}
